home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DATABASE / OBJ1_2.ZIP;1 / C_DBROWS.PRG < prev    next >
Encoding:
Text File  |  1993-01-21  |  9.8 KB  |  312 lines

  1. //*****************************************************************************
  2. // C_DBrows.prg
  3. // Database Browse class for OBJECT v2.03
  4. // Copyright (c) 1991, JHK, JHK-Software, Piestany
  5. // Please compile with: /N/M/W/A
  6. //-----------------------------------------------------------------------------
  7.  
  8. #include "Set.ch"
  9. #include "InKey.ch"
  10. #include "Object.ch"
  11.  
  12. create class DBrowse from Browse
  13.   export:
  14.     var Alias      // ""                    //work area for master database
  15.     var RecNo      // 0                     //RecNo for master database
  16.     var IndexNo    // 0                     //index order for this master database
  17.     var FilterNo   // 0                     //filter # in filter list in this view
  18.     var FilterExp  // ""                    //filter expression associated with 
  19.     var FilterBExp // {||false}             //color code block for TbColumnNew:ColorBlock
  20.     var FilterMark // false                 //to_Mark/to_Hide filtered items
  21.     var OneDbf     // (object of OneDbf)    //update relation area(s)
  22.     method New=DBrowseNew                 //o:New()
  23.     method DoGet=DBrowseDoGet             //o:DoGet()
  24.     method PostInit=DBrowsePostInit       //o:PostInit()         //need for saving selected work area
  25.     method SwapForm=DBrowseSwapForm       //o:SwapForm()         //must be changed for speed optimizing (filter)
  26.     method UpDatabase=DBrowseUpDatabase   //o:UpDatabase()       //set clipper system areas for corectly working this DBrowse
  27.     method UpFilter=DBrowseUpFilter       //o:UpFilter()         //as above...
  28.     method Paint=DBrowsePaint             //o:Paint(isTop)       //allow ::Maximize() before ::Process()
  29.     method VPaint=DBrowseVPaint           //o:VPaint()           //swap database
  30.     method VProcess=DBrowseVProcess       //o:VProcess()         //save RecNo
  31.     private:
  32.     method MakeGet=DBrowseMakeGet         //o:MakeGet(Get)       //local function for o:DoGet()
  33.     endclass
  34.  
  35. //*****************************************************************************
  36. // DBrowse:New() --> self
  37. // initialize new object
  38. //
  39. constructor DBrowseNew()
  40.   ::Alias:= ""
  41.   ::RecNo:= 0
  42.   ::IndexNo:= 0
  43.   ::FilterNo:= 0
  44.   ::FilterExp:= ""
  45.   ::FilterBExp:= {||false}
  46.   ::FilterMark:= false
  47.   ::OneDbf:= (object of OneDbf)
  48.   ::InsBlock:= {|o|DoInsert(o)}
  49.   ::DelBlock:= {|o|DoDelete(o)}
  50.   ::InfoBlock:= {|o|DoInfo(o)}
  51.   ::TestVRecord:={|o,Get|TestVRecord(o,Get)}
  52.   return(self)
  53.  
  54.  
  55. //-----------------------------------------------------------------------------
  56. // DBrowse::DoInsert() --> true/false
  57. // insert new row into database
  58. //
  59. static function DoInsert(DBrowse)
  60.   local i,Rn
  61.   returnif DBrowse:FilterNo>0 with (Alert(ResTxt(192)),false)
  62.   if !DBrowse:SetConfirm or Alert(ResTxt(104),ResTxt(123))==1
  63.     net append blank continue return false
  64.     Rn:=RecNo()
  65.     DBrowse:RecNo:=Rn
  66.     if DBrowse:FormActive
  67.       if DBrowse:MaskFeature
  68.         DBrowse:MaskPaint()
  69.       else
  70.         DBrowse:FormPaint()
  71.       endif
  72.       Eval(DBrowse:InfoBlock,DBrowse)
  73.       DBrowse:SaveIn()
  74.     else
  75.       DBrowse:Tb:Home()
  76.       if IndexOrd()==0
  77.         DBrowse:Tb:GoBottom()
  78.       else
  79.         DBrowse:Tb:GoTop()
  80.         go Rn
  81.       endif
  82.       DBrowse:Tb:RefreshAll()
  83.       StuffKey(K_LEFT)
  84.     endif
  85.     return(true)
  86.   endif
  87.   return(false)
  88.  
  89.  
  90. //-----------------------------------------------------------------------------
  91. // DBrowse::DoDelete() --> true/false
  92. // delete current row from database
  93. //
  94. static function DoDelete(DBrowse)
  95.   if !DBrowse:SetConfirm or Alert(ResTxt(105),ResTxt(123))==1
  96.     net delete continue
  97.     while Deleted(); skip; endwhile Eof()
  98.     if Eof(); go top; endif
  99.     DBrowse:RecNo:=RecNo()
  100.     DBrowse:Tb:Home()
  101.     DBrowse:Tb:RefreshAll()
  102.     return(true)
  103.   endif
  104.   return(false)
  105.  
  106.  
  107. //-----------------------------------------------------------------------------
  108. // DBrowse::DoInfo() --> true
  109. // show Recno,Index,Filter information
  110. //
  111. static function DoInfo(DBrowse)
  112.   DBrowse:InfoMsg:=" "+ResTxt(051)+"="+NTrim(RecNo())+"/"+NTrim(LastRec())+;
  113.                    " "+ResTxt(053)+"="+NTrim(IndexOrd())+;
  114.                    " "+ResTxt(054)+"="+NTrim(DBrowse:FilterNo)+" "
  115.   DBrowse:DoInfo()
  116.   return(true)
  117.  
  118.  
  119. //-----------------------------------------------------------------------------
  120. // DBrowse::TestVRecord(Get) --> true/false
  121. // test is it the record virtual?
  122. //
  123. static function TestVRecord(DBrowse,Get)
  124.   local Ch,n
  125.   default Get to DBrowse:GetList[DBrowse:Tb:ColPos]
  126.   n:=Select(Get:Cargo[nAlias])
  127.   if DBrowse:CanEdit and n>0 and (n)->(RecNo())>(n)->(LastRec())
  128.     if DBrowse:FormActive
  129.       if (n)->(RecNo())>(n)->(LastRec()) and DBrowse:CanAppend
  130.         (n)->(DbGoTop())
  131.         if (n)->(RecNo())>(n)->(LastRec())
  132.           Eval(DBrowse:InsBlock, DBrowse)
  133.         endif
  134.       endif
  135.       if (n)->(RecNo())>(n)->(LastRec())             //record not appended
  136.         Ch:=Alert(ResTxt(079),ResTxt(131))
  137.         do case
  138.           case Ch==2; SetLastKey(K_ESC)                   //close
  139.           case Ch==3; Eval(SetKey(K_ALT_0)); InKeyWait()  //task_list
  140.           case Ch==4; Eval(SetKey(K_F10));   InKeyWait()  //main_menu
  141.           otherwise;  Eval(SetKey(K_F5));    InKeyWait()  //minimize
  142.         endcase
  143.       else
  144.         return(true) //new record appended, ok.
  145.       endif
  146.     else
  147.       Alert(ResTxt(079)) //Browse mode!
  148.     endif
  149.     return(false) //edit not allowed, this is a virtual record!
  150.   endif
  151.   return(true) //ok, edit allowed
  152.  
  153.  
  154. //*****************************************************************************
  155. // DBrowse:DoGet() --> true/false
  156. // checking virtual record and update child relations fields
  157. //
  158. method function DBrowseDoGet()
  159.   local g:=::GetList[::Tb:ColPos]
  160.   returnif !Eval(::TestVRecord,self,g) with false
  161.   return(::MakeGet(g))
  162.  
  163.  
  164. method function DBrowseMakeGet(g)   //need for record_lock (networking)
  165.   local Ch
  166.   local Ok:=true
  167.   if !::CanEdit
  168.     Ok:=::super(Browse):DoGet()
  169.     return(Ok)
  170.   endif
  171.   if (g:Cargo[nAlias])->(NetRLock(true))
  172.     Ok:=::super(Browse):DoGet()
  173.     commit
  174.     (g:Cargo[nAlias])->(DbUnLock())
  175.     if !::FormActive and ::IndexNo>0 and ;
  176.        GetField(g:Name) $ (g:Cargo[nAlias])->(IndexKey(::IndexNo))
  177.       ::Tb:RefreshAll()
  178.     endif
  179.   elseif ::FormActive
  180.     Ch:=Alert(ResTxt(121),ResTxt(130))
  181.     if Ch==2
  182.       SetLastKey(K_ESC)
  183.       Ok:=false
  184.     elseif Ch==3 or Ch==4
  185.       ::SaveIn()
  186.       ::Minimize()
  187.       Eval(SetKey(if(Ch==3,K_ALT_0,K_F10)))
  188.       InKeyWait() //remove nSwapTask
  189.       Ok:=false
  190.     endif
  191.   endif
  192.   return(Ok)
  193.  
  194.  
  195. //*****************************************************************************
  196. // DBrowse:PostInit() --> true
  197. // save/set Alias, go task process
  198. //
  199. method function DBrowsePostInit()
  200.   fill empty ::Alias with Alias()
  201.   fill empty ::OneDbf with GetONeDbf(::Alias)
  202.   return(::super(Browse):PostInit())
  203.  
  204.  
  205. //*****************************************************************************
  206. // DBrowse:SwapForm() --> true
  207. // need for speed optimizing; filter problem, see also DBrowse:UpDatabase()
  208. //
  209. method function DBrowseSwapForm()
  210.   ::RecNo:=RecNo()
  211.   if (::FormActive or ::CanSkip) and ;
  212.      (!(DbFilter()==::FilterExp) or ( ::FilterMark and !Empty(::FilterExp)) )
  213.     SaveDOut(ResTxt(170))
  214.     GoUpFilter(self)
  215.     skip 0
  216.     ::Tb:Configure()
  217.     RestDOut()
  218.   endif
  219.   return(::super(Browse):SwapForm())
  220.  
  221.  
  222. //*****************************************************************************
  223. // DBrowse:UpDatabase() --> true
  224. // set Alias (select), Order (index), filter
  225. //
  226. method function DBrowseUpDatabase()
  227.   if Select()<>Select(::Alias)
  228.     AEval(::OneDbf:Rel,{|e|DbSelectArea(e[2]),DbClearFilter(nil),DbSetOrder(e[3])})
  229.     select (::Alias)
  230.   endif
  231.   set order to (::IndexNo)
  232.   ::UpFilter()
  233.   if ::RecNo==0
  234.     go top
  235.   else
  236.     go ::RecNo
  237.     while Deleted(); skip; endwhile Eof()
  238.     if Eof(); go top; endif
  239.   endif
  240.   ::RecNo:=RecNo()
  241.   return(true)
  242.  
  243.  
  244. //*****************************************************************************
  245. // DBrowse:UpFilter() --> true
  246. // set need filter
  247. //
  248. method function DBrowseUpFilter()
  249.   local i
  250.   if !Empty(::FilterExp)
  251.     if (::FormActive or ::CanSkip) and ;
  252.        (!(DbFilter()==::FilterExp) or ( ::FilterMark and !Empty(::FilterExp)) )
  253.       SaveDOut(ResTxt(170))
  254.       GoUpFilter(self)       //problem!?!? musi byt filter nastaveny aj v relacnych databazach ???
  255.       RestDOut()
  256.     endif
  257.   else
  258.     for i:=1 to ::Tb:ColCount
  259.       (::Tb:GetColumn(i)):ColorBlock:=nil
  260.     endfor
  261.     set filter to
  262.   endif
  263.   return(true)
  264.  
  265.  
  266. static procedure GoUpFilter(DBrowse)
  267.   local i
  268.   if DBrowse:FilterMark
  269.     for i:=1 to DBrowse:Tb:ColCount
  270.       (DBrowse:Tb:GetColumn(i)):ColorBlock:={||if(Eval(DBrowse:FilterBExp),{if(m->tColor>0,nNormal,nNotUse),nUnSelect},{nExtension,nUnSelect})}
  271.     endfor
  272.     set filter to
  273.   else
  274.     set filter to &(DBrowse:FilterExp)
  275.     for i:=1 to DBrowse:Tb:ColCount
  276.       (DBrowse:Tb:GetColumn(i)):ColorBlock:=nil
  277.     endfor
  278.   endif
  279.   return
  280.  
  281.  
  282. //*****************************************************************************
  283. // DBrowse:Paint(isTop) --> true
  284. // swap database and repaint screen
  285. //
  286. method function DBrowsePaint(isTop)
  287.   if !::SetUp; ::PostInit(); endif
  288.   return(::super(Browse):Paint(isTop))
  289.  
  290.  
  291. //*****************************************************************************
  292. // DBrowse:VPaint() --> true
  293. // swap database and repaint screen
  294. //
  295. method function DBrowseVPaint()
  296.   ::UpDatabase()
  297.   return(::super(Browse):VPaint())
  298.  
  299.  
  300. //*****************************************************************************
  301. // DBrowse:VProcess() --> true
  302. // save RecNo
  303. //
  304. method function DBrowseVProcess()
  305.   ::UpDatabase()
  306.   ::super(Browse):VProcess()
  307.   ::RecNo:=RecNo()
  308.   return(true)
  309.  
  310. //------------------------------------------------------- eof (c)JHK ----------
  311.  
  312.